<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;


class AConfigController extends CommonController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $list = \DB::table("config")->where("id",$id)->first();
		
		return view("admin.config.change",['list'=>$list]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $data = \DB::table("config")->where('id',$id)->first();
	
		$aa = $data->status;
		if($aa==0){
			$aa = 1;
			$data = [
						'status'=>$aa
					];
		
			//获取自增id
			$m = \DB::table("config")->where('id',$id)->update($data);
			//判断
					if($m>0){
						$info = "网站已维护！";
					}else{
						$info = "操作失败！";
					}
			return redirect("admin/config")->with("err",$info);
		}else{
				if($aa==1){
					$aa = 0;
					$data = [
								'status'=>$aa
							];
					
					$m = \DB::table("config")->where('id',$id)->update($data);
					//判断
					if($m>0){
						$info = "网站已开启！";
					}else{
						$info = "操作失败！";
					}
					
					 return redirect("admin/config")->with("err",$info);
				}
			}
		
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
